Option Explicit On 
Option Strict On

Imports TreeCreeper01Interfaces

Friend Class cAbundanceCollection
    Implements IAbundanceCollection

    Private pAbundanceCollection As Collection


    Public Sub New()

        pAbundanceCollection = New Collection
    End Sub

    Public ReadOnly Property AbundanceByUniqueKey(ByVal Key As String) As Double Implements IAbundanceCollection.AbundanceByUniqueKey

        Get
            Dim Abundance As Double
            Abundance = CType(pAbundanceCollection.Item(Key), Double)
            Return Abundance
        End Get

    End Property


    Public ReadOnly Property Count() As Integer Implements IAbundanceCollection.Count
        Get
            Count = pAbundanceCollection.Count
        End Get
    End Property

    Public ReadOnly Property AbundanceByIndexBaseOne(ByVal Index As Integer) As Double Implements IAbundanceCollection.AbundanceByIndexBaseOne

        Get
            Dim Abundance As Double
            If Index > 0 And Index <= pAbundanceCollection.Count Then
                Abundance = CType(pAbundanceCollection.Item(Index - 1), Double)
            End If
            Return Abundance
        End Get

    End Property


    Public Sub AddAbundance(ByVal UniqueKey As String, ByVal AbundanceValue As Double) Implements IAbundanceCollection.AddAbundance

        If pAbundanceCollection.Contains(UniqueKey) Then
            Throw New Exception("Source data problem, item '" & UniqueKey & "' should be defined only once! Maybe you are trying to load spatial source data to non-spatial analysis?")
        Else
            pAbundanceCollection.Add(AbundanceValue, UniqueKey)
        End If


    End Sub

End Class
